home *** CD-ROM | disk | FTP | other *** search
- /**
- GRAB Graph Layout and Browser System
-
- Copyright (c) 1986, 1988 Regents of the University of California
- Copyright (c) 1989, Tera Computer Company
- **/
-
- /**
- Contains routines for inserting nodes.
- **/
-
- #include "attribute.h"
- #include "digraph.h"
- #include "screen.h"
- #include "scrdep.h"
- #include "globals.h"
- #include "interf.h"
-
- extern BOOL showbc;
- extern DIGRAPH *digraph, *InitDigraph();
- short hash();
- NODE *CreateNode();
- char *UniqueName();
-
- int DoInsert();
-
- void DoSInsertNode()
- {
- if (digraph == NULL)
- /* first node on an empty screen */
- {
- digraph = InitDigraph();
- }
-
- ChangeText(DoInsert);
- }
-
- static char newtext[MAXSTR];
-
- DoInsert()
- {
- NODE *newnode;
- char newname[MAXSTR];
- int x, y, newx, newy;
-
- IGetCurPos(&x, &y);
-
- newx = SCRX_TO_ABSX(&screen, x);
- newy = SCRY_TO_ABSY(&screen, y);
-
- if (digraph == NULL)
- {
- digraph = InitDigraph();
- }
-
- strcpy(newname, newtext);
-
- if (!Unique(newtext))
- {
- strcpy(newname, UniqueName());
- }
-
- newnode = CreateNode(digraph, newname, newtext, newx, newy);
-
- /* display this node */
- draw_node(digraph, newnode, &screen, TRUE);
-
- IChangeStatusLine("Node Inserted", FALSE);
- graphChanged = TRUE;
- ckpt_done = FALSE;
- }
-
- int EndChangeText();
- static int (*docommand)();
-
- ChangeText(command)
- int (*command)();
- {
- docommand = command;
- IChangeStatusLine("Type node name", FALSE);
-
- TakeTextInput(EndChangeText);
- }
-
- EndChangeText()
- {
- OutofText(newtext);
-
- if (newtext[0] != '\0')
- {
- if (docommand != NULL)
- {
- (*docommand)();
- }
- }
- else
- {
- IChangeStatusLine("No node created", FALSE);
- }
- }
-
- /**
- Unique - returns TRUE if text is unique, else returns FALSE
- **/
-
- Unique(name)
- char *name;
- {
- short hashcode; /* hash code for name */
- VERTEX *curvertex; /* used to chase down the vertex chain */
-
- hashcode = hash(name);
-
- /* chase down the hash list, if any */
- for (curvertex = digraph->hashtbl[hashcode];
- (curvertex != NULL) && (strcmp(curvertex->name, name) != 0);
- curvertex = curvertex->next)
- {
- }
-
- /**
- Only way out of for loop is if curvertex == NULL (name not found)
- or found name (and curvertex != NULL)
- therefore, just need to return NOT of curvertex for true/false
- indicator
- **/
-
- return ((int) (! (curvertex)));
- }
-
- char *UniqueName()
- {
- static char newname[MAXSTR];
- static int uniquenamecounter = 0;
-
- do
- {
- sprintf(newname, "node%d", ++uniquenamecounter);
- } while (! Unique(newname));
-
- return (newname);
- }
-